package com.dex4d.ui.qr;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

import com.dex4d.R;
import com.dex4d.core.AppToolBarBaseActivity;
import com.dex4d.ui.qr.fragment.EasyLoginDoneFragment;
import com.dex4d.ui.qr.fragment.EasyPayDoneFragment;
import com.dex4d.ui.qr.model.PayData;
import com.king.zxing.Intents;

/**
 * 扫码成功回执
 */
public class EasyDoneActivity extends AppToolBarBaseActivity {

    public static void start(Activity activity, String result) {
        Intent intent = new Intent(activity, EasyDoneActivity.class);
        intent.putExtra(Intents.Scan.RESULT, result);
        activity.startActivity(intent);
    }

    public static void start(Activity activity, String result, PayData payData) {
        Intent intent = new Intent(activity, EasyDoneActivity.class);
        intent.putExtra(Intents.Scan.RESULT, result);
        intent.putExtra("PayData", payData);
        activity.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_easy_done;
    }

    @Override
    protected void initVariables() {
        String result = getIntent().getStringExtra(Intents.Scan.RESULT);
        if (result.contains("qrlogin")) {//扫码登录
            getSupportFragmentManager().beginTransaction().add(R.id.container, EasyLoginDoneFragment.newInstance(result)).commit();
        } else if (result.contains("qrpay")) {//扫码支付签名
            PayData payData = getIntent().getParcelableExtra("PayData");
            getSupportFragmentManager().beginTransaction().add(R.id.container, EasyPayDoneFragment.newInstance(result, payData)).commit();
        }
    }

    @Override
    protected void loadData() {

    }

    @Override
    protected void initToolbar() {
        hideBackView();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_trade_ok, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.manger_trade_done) {
            //TODO 待处理
            finish();
            return true;
        } else {
            return super.onOptionsItemSelected(item);
        }
    }
}
